﻿using System;
using System.Windows;
using System.Windows.Data;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BlendModeEffectLibrary;

namespace SLTestHarness
{
	public partial class MainPage : UserControl
	{
		public MainPage()
		{
			InitializeComponent();

			this.gradientEffectsListBox.Items.Add(new NormalEffect());

			this.gradientEffectsListBox.Items.Add(new DarkenEffect());
			this.gradientEffectsListBox.Items.Add(new MultiplyEffect());
			this.gradientEffectsListBox.Items.Add(new ColorBurnEffect());
			this.gradientEffectsListBox.Items.Add(new LinearBurnEffect());

			this.gradientEffectsListBox.Items.Add(new LightenEffect());
			this.gradientEffectsListBox.Items.Add(new ScreenEffect());
			this.gradientEffectsListBox.Items.Add(new ColorDodgeEffect());
			this.gradientEffectsListBox.Items.Add(new LinearDodgeEffect());

			this.gradientEffectsListBox.Items.Add(new OverlayEffect());
			this.gradientEffectsListBox.Items.Add(new SoftLightEffect());
			this.gradientEffectsListBox.Items.Add(new HardLightEffect());
			this.gradientEffectsListBox.Items.Add(new VividLightEffect());
			this.gradientEffectsListBox.Items.Add(new LinearLightEffect());
			this.gradientEffectsListBox.Items.Add(new PinLightEffect());

			this.gradientEffectsListBox.Items.Add(new DifferenceEffect());
			this.gradientEffectsListBox.Items.Add(new ExclusionEffect());

			this.gradientEffectsListBox.Items.Add(new GlowEffect());
			this.gradientEffectsListBox.Items.Add(new ReflectEffect());

			this.gradientEffectsListBox.Items.Add(new HardMixEffect());
			this.gradientEffectsListBox.Items.Add(new NegationEffect());
			this.gradientEffectsListBox.Items.Add(new PhoenixEffect());

			this.gradientEffectsListBox.Items.Add(new AverageEffect());

			this.gradientEffectsListBox.Items.Add(new HueHSVEffect());
			this.gradientEffectsListBox.Items.Add(new SaturationHSVEffect());
			this.gradientEffectsListBox.Items.Add(new ColorHSVEffect());
			this.gradientEffectsListBox.Items.Add(new LuminosityHSVEffect());

			this.gradientEffectsListBox.SelectedIndex = 0;


			this.imageEffectsListBox.Items.Add(new NormalEffect());

			this.imageEffectsListBox.Items.Add(new DarkenEffect());
			this.imageEffectsListBox.Items.Add(new MultiplyEffect());
			this.imageEffectsListBox.Items.Add(new ColorBurnEffect());
			this.imageEffectsListBox.Items.Add(new LinearBurnEffect());

			this.imageEffectsListBox.Items.Add(new LightenEffect());
			this.imageEffectsListBox.Items.Add(new ScreenEffect());
			this.imageEffectsListBox.Items.Add(new ColorDodgeEffect());
			this.imageEffectsListBox.Items.Add(new LinearDodgeEffect());

			this.imageEffectsListBox.Items.Add(new OverlayEffect());
			this.imageEffectsListBox.Items.Add(new SoftLightEffect());
			this.imageEffectsListBox.Items.Add(new HardLightEffect());
			this.imageEffectsListBox.Items.Add(new VividLightEffect());
			this.imageEffectsListBox.Items.Add(new LinearLightEffect());
			this.imageEffectsListBox.Items.Add(new PinLightEffect());

			this.imageEffectsListBox.Items.Add(new DifferenceEffect());
			this.imageEffectsListBox.Items.Add(new ExclusionEffect());

			this.imageEffectsListBox.Items.Add(new GlowEffect());
			this.imageEffectsListBox.Items.Add(new ReflectEffect());

			this.imageEffectsListBox.Items.Add(new HardMixEffect());
			this.imageEffectsListBox.Items.Add(new NegationEffect());
			this.imageEffectsListBox.Items.Add(new PhoenixEffect());

			this.imageEffectsListBox.Items.Add(new AverageEffect());

			this.imageEffectsListBox.Items.Add(new HueHSVEffect());
			this.imageEffectsListBox.Items.Add(new SaturationHSVEffect());
			this.imageEffectsListBox.Items.Add(new ColorHSVEffect());
			this.imageEffectsListBox.Items.Add(new LuminosityHSVEffect());

			this.imageEffectsListBox.SelectedIndex = 0;

			ImageBrush bGradientImageBrush = (ImageBrush)this.Resources["bGradientImageBrush"];
			Binding binding =
				new Binding
				{
					Source = bGradientImageBrush,
					Path = new PropertyPath("Opacity"),
					Mode = BindingMode.TwoWay
				};
			this.bGradientOpacitySlider.SetBinding(Slider.ValueProperty, binding);

			ImageBrush bImageImageBrush = (ImageBrush)this.Resources["bImageImageBrush"];
			binding =
				new Binding
				{
					Source = bImageImageBrush,
					Path = new PropertyPath("Opacity"),
					Mode = BindingMode.TwoWay
				};
			this.bImageOpacitySlider.SetBinding(Slider.ValueProperty, binding);
		}

		private void effectsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			BlendModeEffect effect = e.AddedItems[0] as BlendModeEffect;
			if (effect != null)
			{
				effect.BInput = (ImageBrush)this.Resources["bGradientImageBrush"];
				this.resultBorder.Effect = effect;
			}
		}

		private void imageEffectsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			BlendModeEffect effect = e.AddedItems[0] as BlendModeEffect;
			if (effect != null)
			{
				effect.BInput = (ImageBrush)this.Resources["bImageImageBrush"];
				this.rImage.Effect = effect;
			}
		}
	}
}